package tesis.ProyectoFianl.Overlay;

import java.util.ArrayList;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;


public class MyItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> 
{
	private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
	private Context c;
	private MapView mapView;
//	ActivityMap activityMap;
	
	public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) 
	{
		super(boundCenter(defaultMarker), mapView);
		c = mapView.getContext();
		this.mapView = mapView;
//		this.activityMap = activityMap;
	}

	public void addOverlay(OverlayItem overlay) 
	{
	    m_overlays.add(overlay);
	    populate();
	}

	@Override
	protected OverlayItem createItem(int i) 
	{
		return m_overlays.get(i);
	}

	@Override
	public int size() 
	{
		return m_overlays.size();
	}

	@Override
	protected boolean onBalloonTap(int index, OverlayItem item) 
	{		
//		String nombre = item.getTitle().substring(9);
//		DAOHospital hospital = new DAOHospital(c);
//		Hospital hospitalObejct = hospital.getHospital(nombre);
//		
//		GeoPoint destino = new GeoPoint(
//				   (int)(-26.82156 * 1E6), 
//				   (int)(-65.25555 * 1E6));
////		mapView.getOverlays().clear();
//		Iterator<Overlay> iterator = mapView.getOverlays().iterator();
//		int bandera=0;
//		while(iterator.hasNext())
//		{
//			if(iterator.next().getClass().getName().equals("tesis.ProyectoFianl.Overlay.OverlayRuta"))
//			{
//				bandera=1;
//				OverlayRuta ove =(OverlayRuta) iterator.next();
//				
//				mapView.getOverlays().remove(ove);
//				mapView.invalidate();
//				Log.d("Ocurrencia", "SII");
//				
//			}
//			Log.d("Ocurrencia", ""+iterator.next().getClass().getName());
//		}
//	
//			
//		mapView.getOverlays().remove(mapView.getOverlays().size());
////		mapView.getOverlays().add(new OverlayRuta(item.getPoint(), destino));
////		this.activityMap.DrawPath(item.getPoint(),destino, 1, 1, this.mapView);
//		mapView.postInvalidate();
//		Toast.makeText(c,"presiono index "+hospitalObejct.getNombre()+"\n", Toast.LENGTH_LONG).show();		
		return true;
	}	
}
